import { ReturnType, customError, post } from '..'
import { DetectorTypeInfo, TonSendTransaction, TonTransactionCheck, TonTransactionInfo } from '../interface'
import { URL_TON_CHECK, URL_TON_PURCHASE, URL_TON_UP_SPEED } from '../base/url'

export const upgradeSpeed = async (): Promise<ReturnType<undefined | Array<DetectorTypeInfo>>> => {
    try {
        return await post<Array<DetectorTypeInfo>>(URL_TON_UP_SPEED)
    } catch (error: any) {
        return customError(error)
    }
}

export const check = async (params: TonTransactionCheck): Promise<ReturnType<undefined | TonTransactionInfo>> => {
    try {
        return await post(URL_TON_CHECK, params)
    } catch (error: any) {
        return customError(error)
    }
}

export const purchase = async (params: TonSendTransaction): Promise<ReturnType<undefined>> => {
    try {
        const res = await post(URL_TON_PURCHASE, params)
        // resubmit order info
        if (res.code == 900) {
            res.success = true
        }
        return res
    } catch (error: any) {
        return customError(error)
    }
}
